import { _decorator, Component, EditBox, game, Game, Label, Layout, Node, ScrollView, Slider, Sprite, Toggle, Vec2, Vec3 } from 'cc';
import { UIManager } from '../UIManager';
import { LanauageManager } from '../LanauageManager';
import { GameData } from '../GameData';
import { HttpClient } from '../net/HttpClient';
import { EventManager } from '../EventManager';
import { AudioMgr } from '../AudioMgr';
import { Util } from '../Util';
const { ccclass, property } = _decorator;

@ccclass('popupAnswer')
export class popupAnswer extends Component {

    @property(Label)
    desLab:Label = null;

    @property(Node)
    content:Node = null;

    @property(EditBox)
    editBox:EditBox = null;

    @property(Node)
    sureBtn:Node = null;

    answer1 = ["曾经","意外","沧海难为水", "有一个姑娘~"];

    answer2 = ["世界上最笨的小猫是","小年糕", "花花","富贵"]

    answer3 = ["大声告诉我最帅的人是谁！","李杰"]

    curInde:number = 1;

    curAnswer:string[];
    
    onEnable() {
        this.editBox.node.active = false;
        this.sureBtn.active = false;
        this.content.active = true;

        this.curInde = 1;

        this.refresh();
    }

    refresh(){

        let ans = []
        if (this.curInde == 1){
            this.curAnswer = this.answer1;
        }
        else if (this.curInde == 2){
            this.curAnswer = this.answer2;
        }
        else if (this.curInde == 3){
            this.curAnswer = this.answer3;

            this.editBox.node.active = true;
            this.sureBtn.active = true;
            this.content.active = false;
        }

        this.desLab.string = this.curAnswer[0];

        if(this.content.active){
            for (let index = 0; index < this.content.children.length; index++) {
                const element = this.content.children[index];
                element.getChildByName("Label").getComponent(Label).string = (index==0?"A":index==1?"B":"C") + ": "  + this.curAnswer[index+1];
            }
        }
    }

    onClickHandler(event:Event, str:string){
        if (this.curInde==1 && str == "btn1"){
            this.curInde = 2;
            this.refresh();
        }else if (this.curInde==2 && str == "btn3"){
            this.curInde = 3;
            this.refresh();
        }
        else if (this.curInde==3 && str == "sureBtn" && this.editBox.string == this.answer3[1]){ 
            GameData.curstep = 1;
            EventManager.eventTarget.emit(EventManager.REFRESH_GAME);
            this.closeView();
        }
        else{
            UIManager.open(UIManager.uiNamePath.popupResult);
        }
    }

    closeView(){
        UIManager.close(this.node);
    }
}

